﻿ <script type="text/javascript">
     $(document).ready(function () {
         var source = init();
         initheader(source);
         initbody(source);
     });
     function init() {
         var source = new datasource();
         source.c = window.c;
         source.init();
         return source;
     }
     function initheader(source) {
         $('#main .m-title').html(source.title);
     }
     function initbody(source) {
         source.onLoad = function (data) {
             var rows = formatdata(source,data);
             initdatalist(rows);
         }
         source.load();
     }
     function initfooter() {
       
     }
     function formatdata(source,data) {
         var mainColumns = ["ROWINDEX", 'CODE', 'TOWHNO', 'STATE'];
         var subColumns = ['THEDRIVER', 'CARNO', 'CREATEDBY', 'CREATIONDATE'];
         var rss = [];
         for (var r in data.rows) {
             var rr = data.rows[r]
             var t = styletext(source, mainColumns, subColumns, rr);
             rss.push({ text: t, value: rr });
         }
         return rss;
     }
     function initdatalist(rows) {
         $(".easyui-datalist").datalist({
             fit: true,
             lines: true,
             border: false,
             textFormatter: function (value) {
                 return '<a href\'javascript:void(0)\' class=\'datalist-link\'>' + value + '</a>';
             },
             onClickRow: function (index, row) {
                 $('#main .m-title').html(row.value.maintext);
                 $('#main').panel('refresh', 'Views/test.htm');
             },
             data: rows
         });
     }
     function styletext(source, maincols,subcols, row) {
         var s = "";
         var maintext = farmattext(source, maincols, row);
         var subtext = farmattext(source, subcols, row);
         var mark = "";
         if (row.REMARK && row.REMARK != "") {
             mark = row.REMARK;
         }
         if (mark != "")
             mark = "</br>" + mark;
         s += '<div style="font-size:16px;font-weight:bold">' + maintext + '</div>';
         s += '<div style="line-height:24px">' + subtext + mark + '</div>';
         row.maintext = maintext;
         return s;
     }
     function farmattext(data, cols, row) {
         var text = "";
         for (var i in cols) {
             var n = cols[i];
             var item = data.getitem(n);
             var vvv = "";
             if (item && item.foreign && item.foreign.isfkey) {
                 var fn = item.foreign.displayname;
                 vvv = row[fn];
             }
             if (item && item.comvtp && item.comvtp.isvtp) {
                 for (var v in item.comvtp.items) {
                     var com = item.comvtp.items[v];
                     if (com.Value == row[n]) {
                         vvv = com.Text;
                         break;
                     }
                 }
             }
             if (vvv == "")
                 vvv = row[n];
             if (vvv != null) {
                 if (text == "")
                     text = vvv;
                 else
                     text += "&nbsp;" + vvv;
             }
         }
         return text;
     }
</script>
<ul class="easyui-datalist">
</ul>

